#include "aiot_config.h"

bool aiot_clear_config(const char *path)
{
    FILE* fd = NULL;

    fd = fopen(path, "w+");
    if (fd == NULL)
    {
        return false;
    }

    fclose(fd);
    return true;
}

bool aiot_save_config(const char *path, const char *clientid, const char *username, const char *password)
{
    bool  res  = false;
    FILE* fd   = NULL;
    int   optr = -1;

    if(clientid == NULL || username == NULL || password == NULL)
    {
        return res;
    }

    fd = fopen(path, "w+");
    if (fd == NULL)
    {
        return res;
    }

    optr = fprintf(fd, "{\"clientid\":\"%s\",\"username\":\"%s\",\"password\":\"%s\"}\n", clientid, username, password);
    if (optr > 0)
    {
        res = true;
    }

    fclose(fd);
    return res;
}
